﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 树
{
    class BSTNode<T> where T : IComparable<T>
    {
        /// <summary>
        /// 左子节点，可空
        /// </summary>
        public BSTNode<T> ChildLeft { get; internal protected set; }
        /// <summary>
        /// 右子节点，可空
        /// </summary>
        public BSTNode<T> ChildRight { get; internal protected set; }
        /// <summary>
        /// 父节点，不可为空
        /// </summary>
        public BSTNode<T> Parent { get; internal protected set; }
        /// <summary>
        /// 平衡因子 有效范围(-1, 0, 1) 左-右
        /// </summary>
        public int BalanceFactor { get; internal protected set; }
        /// <summary>
        /// Node再插入时自己记录高度，可以节省每次获取高度时的递归计算
        /// </summary>
        public int Height { get; internal protected set; }
        /// <summary>
        /// 自定义数据类型
        /// </summary>
        public T Data { get; set; }

        public BSTNode() {}

        public BSTNode(T t) { Data = t; }

        public override string ToString()
        {
            return Data == null ? "no data" : Data.ToString();
        }
    }
}
